//
//  ViewController.m
//  LGCharts
//
//  Created by lg on 2019/5/16.
//  Copyright © 2019 lg. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) NSMutableArray<NSDictionary *> *dataSource;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"LGCharts";
    self.view.backgroundColor = UIColor.whiteColor;
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuseIdentifier"];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    }
    cell.textLabel.text = self.dataSource[indexPath.row].allKeys.firstObject;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UIViewController *viewController = [[NSClassFromString(self.dataSource[indexPath.row].allValues.firstObject) alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
}

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [@[
                         @{@"雷达图" : @"LGRadarChartViewController"},
                         @{@"折线图" : @"LGLineChartViewController"},
                         @{@"柱形图" : @"LGBarChartViewController"},
                         @{@"饼状图" : @"LGPieChartViewController"}
                         ] mutableCopy];
    }
    return _dataSource;
}

@end
